<?php

namespace app\index\validate;

use app\index\service\OptService;
use think\Validate;

class Bid extends Validate
{

    protected $rule = [
        'id' => 'require|number',
        'name' => 'require',
        'chanid' => 'require|number',
        'business' => 'require|number',
        'type' => 'check_type',
        'bidding_type' => 'check_bidding_type',
        'qualification' => 'check_qualification',
        'bid_type' => 'check_bid_type',
        'bid_evaluation' => 'check_bid_evaluation',
    ];

    protected $message = [
        'id' => '网络错误',
        'name' => '请填写项目名称',
        'chanid' => '项目所属单位',
        'business' => '请选择项目属性',
    ];

    protected $scene = [
        'add' => ['name','chanid','bidding_type','qualification','bid_type','bid_evaluation'],
        'edit' => ['id','name','chanid','bidding_type','qualification','bid_type','bid_evaluation'],
    ];

    public function check_type($value){
        if(!(new OptService())->check_option_exists('bid_type',$value)){
            return '请选择项目类型';
        }
        return true;
    }

    public function check_bidding_type($value){
        if(!(new OptService())->check_option_exists('bid_bidding_type',$value)){
            return '请选择招标方式';
        }
        return true;
    }

    public function check_qualification($value){
        if(!(new OptService())->check_option_exists('bid_qualification',$value)){
            return '请选择资格审查';
        }
        return true;
    }

    public function check_bid_type($value){
        if(!(new OptService())->check_option_exists('bid_bid_type',$value)){
            return '请选择投标方式';
        }
        return true;
    }

    public function check_bid_evaluation($value){
        if(!(new OptService())->check_option_exists('bid_bid_evaluation',$value)){
            return '请选择评标方式';
        }
        return true;
    }


}















